<?php
ob_start();
session_start();
include "checksession.php";
date_default_timezone_set('Asia/Bangkok');
include("../connect.php");
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

$strSQL = "SELECT * FROM prd_type where type_id = '".$_GET["type_id"]."' ";
$objQuery = mysql_query($strSQL);
$objResult = mysql_fetch_array($objQuery);
$type_id = $objResult["type_id"];
if(!$objResult)
{
	echo "Not found id=".$_GET["type_id"];
}
else
{
?>
<html>
<head>
<title>Adinop Co., Ltd. was founded as an ingredients importer and local manufacturers’ distributor in 1986. We also function as an exporter of finished products</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" href="../css/style.css"/>
<link type="text/css" href="../css/ui-lightness/jquery-ui-1.7.2.custom.css" rel="stylesheet" />
<script src="../js/jquery/jquery-1.4.3.min.js" type="text/javascript"></script>
<script type="text/javascript" src="../js/jquery/jquery-ui-1.7.2.custom.min.js"></script>
<script type="text/javascript" src="../js/jquery/timepicker.js"></script>
</head>

<script language="javascript">
			function CheckValidate()
			{
			if(eval("document.frmMain.txttypename.value")==""){
				alert("กรุณากรอกช่อง Type Name");
				eval("document.frmMain.txttypename.focus();")
				return false;
				}
			}
</script>

</script>
<body>
   <body class="body">

            <table align="center" width="90%">
                <tr>
                    <td colspan="2" class="header" >
                      <img src="../images/logo.png"> ประเภทอุปกรณ์ 
                        <hr/>
                    </td>
                </tr >
              </table>
<br/>
<div align="center">
 <fieldset>
<legend class="nameTitle">แก้ไขข้อมูล</legend>
<form action="<? $editFormAction;?>" method="post" name ="frmMain" id="frmMain" OnSubmit="return CheckValidate();" />
<table width="100%" border="0" class="inputcontenttable">
  <tr>
    <th width="50%">
      <div align="right">Type ID : </div></th>
    <th><div align="left">
      <input type="text" name="txttypeid" id="txttypeid" size="20" value="<?=$objResult["type_id"];?>" maxlength= "8" readonly="" />
  </tr>

   <tr>
    <th width="50%">
      <div align="right">Type Name : </div></th>
    <th><div align="left">
      <input type="text" name="txttypename" id="txttypename" size="20" value="<?=$objResult["type_name"];?>"/>
  </tr>
</table>
<br/>
 </fieldset>
<br/>
<input name="btnTypeedit" type="submit" id="btnTypeedit" value="แก้ไข" style="height: 30px; width: 120px" />
</form>
</div>
<br/>
</fieldset>


</body>
  <? 
	  if(isset($_POST['btnTypeedit'])){
	  $txttypeid = $_POST['txttypeid'];
	  $txttypename = $_POST['txttypename'];
		
	  $sql3 = "select * from prd_type where type_name = '$txttypename' and type_id != '$txttypeid' ";
	  $query_id3 = mysql_query($sql3);
	  if(mysql_num_rows($query_id3) > 0){
		echo "	<script language='javascript'>
				alert('ชื่อประเภทซ้ำ');
				</script>";
				exit();
		}
		
		else{
?>
<?
	
		$sql1 = "update prd_type set type_name= '$txttypename' where type_id ='$txttypeid' ";
		$rsUpdate=mysql_query($sql1);

	   if($rsUpdate){
		echo "<script language='javascript'>
			   alert('Update Complete');
			   setTimeout(\"parent.$.fancybox.close()\",1000); 
			  </script>";
		 echo "<meta http-equiv='refresh' content='1; url=typeIT.php'>";
		}
	}
}
}

  mysql_close($connection);
  ?>

</html>